package top.haijunit.work.core.doamin;

import lombok.Getter;

/**
 * 【说明类功能】
 *
 * @author zhanghaijun
 * @since 2024-08-07
 */
@Getter
public class ExceptionServer extends RuntimeException {

    public ExceptionServer(ExceptionEnum exception, Throwable e) {
        this("server exception, code: %s, message: %s", exception.getCode(), e, exception.getMessage());
    }

    public ExceptionServer(ExceptionEnum exception) {
        this("server exception, code: %s, message: %s", exception.getCode(), exception.getMessage());
    }

    public ExceptionServer(String message, Object... params) {
        this(String.format(message, params));
    }

    public ExceptionServer(String message, Throwable e, Object... params) {
        this(String.format(message, params), e);
    }

    public ExceptionServer(String message) {
        super(message);
    }

    public ExceptionServer(String message, Throwable throwable) {
        super(message, throwable);
    }

    /**
     * 自定义异常不需要堆栈，提高性能
     */
    @Override
    public synchronized Throwable fillInStackTrace() {
        return this;
    }
}
